package com.prestamomo.vil.ppa.pmvilpage.pmfitter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.prestamomo.vil.ppa.R;

import java.util.List;

/**
 * 创建日期：2023/12/1
 * 文件名称：PmvilXIanFitter
 * 文件描述：
 */
public class PmvilXIanFitter extends RecyclerView.Adapter<PmvilXIanFitter.Holed> {

    private Context pmComt;
    private List<Uri> pmmList;

    public PmvilXIanFitter(Context pmComt, List<Uri> pmmList) {
        this.pmComt = pmComt;
        this.pmmList = pmmList;
    }

    @NonNull
    @Override
    public Holed onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new Holed(LayoutInflater.from(pmComt).inflate(R.layout.itme_xpj,parent,false));
    }


    @Override
    public void onBindViewHolder(@NonNull Holed holder, @SuppressLint("RecyclerView") int position) {
        if(pmmList.get(position)==null){
            holder.img_close.setVisibility(View.GONE);
            Glide.with(pmComt).load(R.mipmap.place_pmvil_icon1).into(holder.img_cot);
        }else{
            holder.img_close.setVisibility(View.VISIBLE);
            Glide.with(pmComt).load(pmmList.get(position)).into(holder.img_cot);
        }

        holder.img_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mPmlIseItmCliw!=null){
                    mPmlIseItmCliw.delectImt(position);
                }
            }
        });
        holder.img_cot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mPmlIseItmCliw!=null&&pmmList.get(position)==null){
                    mPmlIseItmCliw.pailwei();
                }
            }
        });
    }


    @Override
    public int getItemCount() {
        return pmmList==null?0:pmmList.size();
    }

    public void setDate(List<Uri> imgList) {
        this.pmmList = pmmList;
        notifyDataSetChanged();
    }

    public class Holed extends RecyclerView.ViewHolder{
        ImageView img_cot;
        ImageView img_close;
        public Holed(@NonNull View itemView) {
            super(itemView);
            img_cot = itemView.findViewById(R.id.img_cot);
            img_close = itemView.findViewById(R.id.img_close);
        }
    }

    public interface PmlIseItmCliw{
        void pailwei();
        void delectImt(int postion);
    }

    private PmlIseItmCliw mPmlIseItmCliw;

    public void setPmlIseItmCliw(PmlIseItmCliw pmlIseItmCliw) {
        mPmlIseItmCliw = pmlIseItmCliw;
    }
}
